<?php

namespace CNEPAdmin\Controller;

use CNEPAdmin\Controller\CommonController;

class GoodsCatController extends CommonController {

  protected $_modelName = "GoodsCat";

    protected function setCode() {
        $this->_code = "Goods"; // 属于系统管理模块
    }

    protected function _getQueryArr(&$where,&$order) {
        $where = array();

        $where['isOn'] = 1;
        if (strlen ( trim ( I ( "sCatName" ) ) ) > 0) {
        	$where ['catName'] = array (
        		"like",
        		"%" . trim ( I ( "sCatName" ) . "%" )
        	);
        }
        if (strlen ( trim ( I ( "sCommentType" ) ) ) > 0 && intval ( I ( "sCommentType" ) ) >= 0) {
        	$where ['commentType'] = array (
        		"eq",
        		intval ( I ( "sCommentType" ) )
        	);
        }

        $orderBy = 'addTime';
        $desc = 'desc';
        if (intval(I("sDesc")) === 1) {
            $desc = 'asc';
        }
        if (strlen(trim(I("sOrderBy", ''))) > 0) {
            $orderBy = I("sOrderBy");
        }

        $order = array(
            $orderBy => $desc
        );
    }
    
    /**
     * 查看列表
     */
    public function index() {
        $this->checkPriv('cat', 1, false);

        $this->_getOnePageData("getGoodsCatList", "getGoodsCatListLength");
    }

    public function saveGoodsCat() {
        $id = intval(I("post.catID"));
        
        if($id > 0) {
            $this->updateGoodsCat();
        } else {
            $this->addGoodsCat();
        }
        
    }
    
    /**
     *  添加
     */
    public function addGoodsCat() {
        $this->_ajaxOperate('addGoodsCat', 'cat', 2);
    }

    /**
     * 更新基本信息(需要更新什么就提交什么)
     */
    public function updateGoodsCat() {
        $this->_ajaxOperate('updateGoodsCat', 'cat', 2);
    }

    /**
     * 删除
     */
    public function deleteGoodsCat() {
        $this->_ajaxOperate('deleteGoodsCat','cat', 2, I("catID"));
    }
}
